// 无重复数字的最长子串
//   abcabcbb =》abc
/**
 * @param {string} s
 * @return {number}
 */

var lengthOfLongestSubstring = function (s) {
  let len = s.length
  let result = 0
  let start = 0
  let myMap = new Map()

  for (let i = 0; i < len; i++) {
    if (myMap.has(s[i])) {
      start = Math.max(start, myMap.get(s[i]) + 1)
    }
    myMap.set(s[i], i)
    result = Math.max(result, i - start + 1)
  }

  return result
};

console.log(lengthOfLongestSubstring('abcabcbb')); // 应该输出 1
